package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.utils.base.UuidUtil;
import com.entity.Login;
import com.entity.User;
import com.repository.LoginDao;
import com.service.base.BaseServiceImp;

@Service("LoginService")
public class LoginServiceImpl extends BaseServiceImp<Login> implements LoginService{

	@Autowired
	private LoginDao loginDao;
	@Autowired
	private UserService userService;
	
	@Override
	public String insert(Login o) {
		o.setId(UuidUtil.get32UUID());
		o.setEncryption("SHA");
		baseDao.insert(o);
		return o.getId();
	}

	@Override
	public int countPwd(Login login) {
		return loginDao.countPwd(login);
	}

	@Override
	@Transactional
	public String reg(Login o, User u) {
		o.setId(UuidUtil.get32UUID());
		o.setEncryption("SHA");
		loginDao.insert(o);
		// 添加用户表
		u.setLoginId(o.getId());
		u.setUserName(o.getAccount());
		userService.register(u);
		return o.getId();
	}
	
}
